import { MyFileDir } from '../model/models/MyFileDirTable'
import { Op } from "sequelize";
import { deleteFile } from "./dataInit"
import {staticPath} from "../utils/const"
import path from 'path';

/**
 * @description: 通过名字模糊删除数据
 * @param {string} name 
 * @return {Promise<number>} 返回影响行数
 * @author: tao wenbo 2419421809@qq.com
 */
export async function deleteByName( name: string ){
    // let all = await MyFileDir.findAll({
    //     where: {
    //         path: {
    //             [Op.like]: `%${name}%`
    //         }
    //     }
    // })
    // for( let i of all ){
    //     let p = path.join(staticPath, i.dataValues.path)
    //     await deleteFile( p )
    // }

    let res = await MyFileDir.destroy({
        where: {
            path: {
                [Op.like]: `%${name}%`
            }
        }
    })
    return res
}